package com.hex.liyue.lookingdatemodule.activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.hex.liyue.R;
import com.hex.liyue.commonmodule.activity.BaseActivity;
import com.hex.liyue.commonmodule.bean.BaseBean;
import com.hex.liyue.commonmodule.utils.L;
import com.hex.liyue.commonmodule.utils.StatusBarCompatUtils;
import com.hex.liyue.commonmodule.utils.T;
import com.hex.liyue.lookingdatemodule.presenter.AboutPresenter;
import com.hex.liyue.lookingdatemodule.presenter.IAboutView;

import butterknife.Bind;
import butterknife.OnClick;


/**
 * 举报界面
 * Created by WJ on 2016/6/18.
 */
public class AboutActivity extends BaseActivity implements IAboutView, TextWatcher, CompoundButton.OnCheckedChangeListener {
    @Bind(R.id.tv_toobar_title)
    TextView tvToobarTitle;
    @Bind(R.id.iv_toobar_back)
    ImageView ivToobarBack;
    @Bind(R.id.tv_toobar_right)
    TextView tvToobarRight;
    @Bind(R.id.tv_enter_word)
    TextView tv_enter_word;
    @Bind(R.id.et_enter)
    EditText et_enter;
    @Bind(R.id.iv_pron)
    CheckBox iv_pron;
    @Bind(R.id.iv_fraud)
    CheckBox iv_fraud;
    @Bind(R.id.iv_insult)
    CheckBox iv_insult;
    @Bind(R.id.iv_harassment)
    CheckBox iv_harassment;
    @Bind(R.id.iv_political)
    CheckBox iv_political;
    @Bind(R.id.iv_report)
    CheckBox iv_report;


    private AboutPresenter aboutPresenter;
    private boolean isAll = false;
    private int num = 50;
    private CharSequence temp;
    private int selectionStart;
    private int selectionEnd;
    private String pron, fraud, insult, harassment, political, report;
    private String[] reason=new String[6];

    @Override
    protected void bindPresenter() {
        aboutPresenter = new AboutPresenter(this);
    }

    @Override
    protected void initData(Bundle extras) {
        et_enter.addTextChangedListener(this);
        iv_report.setOnCheckedChangeListener(this);
        iv_fraud.setOnCheckedChangeListener(this);
        iv_harassment.setOnCheckedChangeListener(this);
        iv_pron.setOnCheckedChangeListener(this);
        iv_insult.setOnCheckedChangeListener(this);
        iv_political.setOnCheckedChangeListener(this);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_about;
    }

    @Override
    protected void initToolbar() {
        StatusBarCompatUtils.compat(this);
        tvToobarTitle.setText("举报");
        ivToobarBack.setVisibility(View.VISIBLE);
        tvToobarRight.setVisibility(View.VISIBLE);
        tvToobarRight.setText("提交");
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        switch (buttonView.getId()) {
            case R.id.iv_pron:
                if (isChecked) {
                    pron = "色情";
                } else {
                    pron = " ";
                }
                break;
            case R.id.iv_fraud:
                if (isChecked) {
                    fraud = "欺诈";
                } else {
                    fraud = " ";
                }
                break;
            case R.id.iv_insult:
                if (isChecked) {
                    insult = "侮辱/诋毁";
                } else {
                    insult = " ";
                }
                break;
            case R.id.iv_harassment:
                if (isChecked) {
                    harassment = "广告骚扰";
                } else {
                    harassment = " ";
                }
                break;
            case R.id.iv_political:
                if (isChecked) {
                    political = "政治";
                } else {
                    political = " ";
                }
                break;
            case R.id.iv_report:
                if (isChecked) {
                    report = "侵权举报";
                } else {
                    report = " " ;
                }
                break;
        }
    }
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        temp = s;
    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }
    @OnClick({R.id.iv_toobar_back, R.id.tv_toobar_right})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_toobar_back:
                onBackPressed();
                break;
            case R.id.tv_toobar_right:
                et_enter.addTextChangedListener(this);
                reason[0]=pron;
                reason[1]=fraud;
                reason[2]=insult;
                reason[3]=harassment;
                reason[4]=political;
                reason[5]=report;
                String reasons="";
                for(int i = 0; i < reason.length; i++){
                    if(null!=reason[i]){
                        reasons=reasons+reason[i];
                    }
                }
                L.e(reasons,reasons);
                String m=pron + "" + insult + "" + fraud + "" + harassment + "" + political + "" + report;
                aboutPresenter.getReport(getIntent().getStringExtra("uid"),getIntent().getStringExtra("look"),reasons, et_enter.getText().toString());
                finish();
                T.show(AboutActivity.this, "举报成功", 1);
                break;
        }
    }


    @Override
    public void afterTextChanged(final Editable s) {

        int number = num - s.length();
        if (number >= 0) {
            tv_enter_word.setText("还可输入 " + number + " 字");
        } else {
            tv_enter_word.setText("还可输入 " + 0 + "字");
        }
        selectionStart = et_enter.getSelectionStart();
        selectionEnd = et_enter.getSelectionEnd();
        if (temp.length() > num) {
            T.show(AboutActivity.this, "最多50个字哦", 1);
        }
    }

    @Override
    public void showLod(String msg) {
        showLoad(this, msg);
    }

    @Override
    public void closeLod() {
        closeLoad();
    }

    @Override
    public void showT(String msg) {
        showToast(this, msg);
    }


    @Override
    public void setAdapter(BaseBean baseBean) {

    }
}
